package com.hfb.mashibing.alip8.spring.mapper;

import com.hfb.mashibing.alip8.spring.entity.Person;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface PersonMapper {

    //使用@Select注解指明getById方法要执行的SQL
    @Select("select * from person where id=#{id}")
    @ResultMap("person")
    Person getById(int id);

    //使用@Select注解指明getAll方法要执行的SQL
    @Select("select * from person")
    @Results(id = "person", value = {
        @Result(property = "id",column = "id",id = true),
        @Result(property = "name",column = "name"),
        @Result(property = "age",column = "age"),
        @Result(property = "sex",column = "sex"),
//        @Result(property = "arrays",column = "arrays"),
//        @Result(property = "lists",column = "lists"),
//        @Result(property = "maps",column = "maps"),
//        @Result(property = "likes",column = "likes")
    })
    List<Person> getAll();

    //使用@Insert注解指明add方法要执行的SQL
    @Insert("insert into person(name,age,sex) values(#{name},#{age},#{sex})")
    int add(Person user);

    //使用@Update注解指明update方法要执行的SQL
    @Update("update person set name=#{name},age=#{age},sex=#{sex} where id=#{id}")
    int update(Person user);

    //使用@Delete注解指明deleteById方法要执行的SQL
    @Delete("delete from person where id=#{id}")
    int deleteById(int id);

}
